home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
TEGL6B.ARJ
/
TUTOR.COM
/
FRAMES.TXT
< prev
next >
Wrap
Text File
|
1991-08-16
|
6KB
|
215 lines
FRAMES
-------------------------------------------------------------------
Frames are the core items to the window manager. You create a frame
using a PushImage then save the global variable StackPtr to
manipulate it and to recognise it. StackPtr is of the TYPE
ImageStackPtr. Since this is a pointer it will always be unique to
the frame.
Here we create a frame that covers the area (50,50,200,150) on the
screen.
BEGINFILE> frame1.pas
{-- frame1.pas}
USES teglunit,teglmain;
VAR ifs : ImageStkPtr;
BEGIN
easytegl;
easyout;
PushImage(50,50,200,150);
ifs := StackPtr;
TeglSupervisor;
END.
ENDFILE>
Notice that we start our program with tegleasy and easyout. It's a
good idea to start your programs this way when you are first
learning how to use the TEGL WINDOWS TOOLKIT because they provide a
simplified startup and a way to exit the program.
Specifically tegleasy initializes the graphics system (autodectects
the graphics hardware), the virtual memory manager, the window
manager and it clears the screen too! Easyout places a button in
the lower left corner of the screen that will terminate the program
when it is clicked on. This may seem trivial but in a GUI there has
to be an event to make the program finish, TeglSupervisor never
returns, it just loops waiting for an event.
This little program isn't very useful yet because all we have done
is saved the area that this frame covers. If you run it you won't
see anything on the screen to show where the frame is. However, if
you click the right mouse button down and move it around the screen
will will find that there is an invisible frame there that can been
moved. The right mouse button can be used to click on and move any
mobile frame. Lets change it by covering it with something so we
can see it.
BEGINFILE> frame2.pas
{-- frame2.pas}
USES teglunit,teglmain;
VAR ifs : ImageStkPtr;
BEGIN
easytegl;
easyout;
PushImage(50,50,200,150);
ShadowBox(50,50,200,150);
ifs := StackPtr;
TeglSupervisor;
END.
ENDFILE>
Here we have added a line calling the routine ShadowBox. This just
blanks the frame and places a shadowed edge around it. You could
clear the frame by using the bar command like so:
SetViewPort(0,0,GetMaxx,GetMaxy,Clipoff);
SetFillStyle(SolidFill,White);
Bar(50,50,200,150);
SetColor(Black);
Rectangle(50,50,200,150);
This would blank the frame to white and draw a black line around
it. ShawdowBox isn't much move complicated, but it is ready to use.
You're probably wondering why we keep saving the StackPtr. Like we
said earlier, you'll need this to manipulate the frame. So lets use
it.
The next example adds a button and an associated event to the
frame.
BEGINFILE> frame3.pas
{-- frame3.pas}
{$F+}
USES teglunit,teglmain;
VAR ifs : ImageStkPtr;
function cancelevent(frame: ImageStkPtr; mouse: MsClickPtr): Word;
BEGIN
dropstackimage(ifs);
END;
BEGIN
easytegl;
easyout;
PushImage(50,50,200,150);
ShadowBox(50,50,200,150);
ifs := StackPtr;
DefineSquareButtonText(ifs,0,0,80,30,5,5,'CANCEL',cancelevent);
TeglSupervisor;
END.
ENDFILE>
After compiling and running this you'll probably agree that those
squarebuttons look OK.
Now lets add some action to it. This example will press and release
the button. Try holding the left mouse button down and passing it
over the button repeatedly.
BEGINFILE> frame4.pass
{-- frame4.pas}
{$F+}
USES teglunit,teglmain;
VAR ifs : ImageStkPtr;
function cancelevent(frame: ImageStkPtr; mouse: MsClickPtr): Word;
BEGIN
{-- this will press the button down and if the mouse button }
{-- is release WHILE it is over the button it will return }
{-- TRUE. If the mouse cursor passes out of the button without }
{-- being released then it will return FALSE and }
{-- releasesquarebutton will be called automatically. }
if visualsquarebuttonpress(frame,mouse) then
begin
{-- was TRUE, we release the button }
releasesquarebutton(frame,mouse);
{-- then dispose of the frame. }
dropstackimage(ifs);
end;
END;
BEGIN
easytegl;
easyout;
PushImage(50,50,200,150);
ShadowBox(50,50,200,150);
ifs := StackPtr;
DefineSquareButtonText(ifs,0,0,70,30,5,5,'CANCEL',cancelevent);
TeglSupervisor;
END.
ENDFILE>
At some point you will likely have more than one frame on the
screen. When the mouse clicks on that frame it would be nice to
have it on top of all the other frames.
SetAutoRotate(OnOff: Boolean);
This sets the automatic rotation of frames. If set to TRUE then any
frame that is clicked on will come to the top of the stack (be the
topmost, and entirely visible).
This example will put 25 frames on the screen. Try running it with
autorotate set to FALSE also. Try moving the frames around (using
the right mouse button).
BEGINFILE> frame5.pas
{-- frame5.pas}
{$F+}
USES teglunit,teglmain;
function cancelevent(frame: ImageStkPtr; mouse: MsClickPtr): Word;
BEGIN
if visualsquarebuttonpress(frame,mouse) then
begin
{-- was TRUE, we release the button }
releasesquarebutton(frame,mouse);
{-- then dispose of the frame. }
dropstackimage(frame);
end;
END;
VAR ifs : ImageStkPtr;
i : Integer;
BEGIN
easytegl;
easyout;
setautorotate(true);
for i := 1 to 25 do
BEGIN
quickframe(ifs,i*10,i*10,150,100);
DefineSquareButtonText(ifs,0,0,70,30,5,5,'CANCEL',cancelevent);
END;
TeglSupervisor;
END.
ENDFILE>